package com.syezon.wifikey.app;

import android.app.Application;
import android.arch.persistence.room.Room;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.hodanet.appadvplatclient.AdvClient;
import com.syezon.android.base.netstatus.NetStateReceiver;
import com.syezon.wifikey.ad.AdConfig;
import com.syezon.wifikey.channel.ChannelConfig;
import com.syezon.wifikey.crash.CrashHandler;
import com.syezon.wifikey.db.WifiDatabase;
import com.syezon.wifikey.splash.FrontADService;
import com.syezon.wifikey.utils.Utils;
import com.syezon.wifikey.wxapi.WXConstant;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.commonsdk.UMConfigure;

/**
 * Created by Administrator on 2018/9/4.
 */

public class WiFiKeyApp extends Application {

    private static WiFiKeyApp mApp;
    private static WifiDatabase db;

    /**
     * @return 获取应用上下文
     */
    public static WiFiKeyApp getAppContext() {
        return mApp;
    }

    /**
     * @return
     */
    public static WifiDatabase getDatabase() {
        return db;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;
        Utils.init(this);
        AdvClient.getInstance().init(this, AdConfig.APP_ID);
        CrashHandler.getInstance().init(this);
        FrontADService.getInstance().init();
        initDatabase();
        initWechatSDK();
//        initFeedBack();
        NetStateReceiver.registerNetworkStateReceiver(this);
        UMConfigure.init(this, "59084ea65312dd0c04001446", ChannelConfig.getChannel(), UMConfigure.DEVICE_TYPE_PHONE, "23709a8c0271c39e70a943a5f02cced7");

        //new UPush().initAndRegister(this);
    }

    private void initWechatSDK() {
        //微信SDK初始化
        try {
            IWXAPI iwxapi = WXAPIFactory.createWXAPI(this, WXConstant.APP_ID, true);
            iwxapi.registerApp(WXConstant.APP_ID);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initDatabase() {
        db = Room.databaseBuilder(getApplicationContext(), WifiDatabase.class, "wifi_pwd")
                .allowMainThreadQueries()
                .build();
    }

//    private void initFeedBack() {
//        try {
//            FeedbackAPI.init(this, "24548469", "fb78c739ac6eb4d9db9c7ac86a3562bb");
//        } catch (Exception e) {
//
//        }
//    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
